package com.file;

import com.sun.org.apache.regexp.internal.RE;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.RandomAccessFile;

/**
 * 动态文件类
 */
public class 动态输入流 {
    public static void main(String[] args) {

        String path = String.format("D:%s7788%sfuck%srandom.txt", File.separator,File.separator,File.separator);
        File file = new File(path);
        try {
            RandomAccessFile randomAccessFile = new RandomAccessFile(file,"rw");
            file.delete();
            if(!file.exists()){
                file.createNewFile();
            }
            String content = new String("阴天，多云，小雨，大风，中雨，小雪，雷阵雨".getBytes("GBK"),"ISO-8859-1");
            randomAccessFile.writeBytes(content);
            System.out.println(String.format("当前文件指针:%s",randomAccessFile.getFilePointer()));
            randomAccessFile.seek(0);
           byte[] b = new byte[2];
           int len ;
           while ((len = randomAccessFile.read(b,0,2)) != -1){
               System.out.println(new String(b,0,len));
           }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
